package com.ftwj.service.impl;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ftwj.entity.SysRoleMenu;
import com.ftwj.mapper.SysMenuListMapper;
import com.ftwj.mapper.SysRoleMenuMapper;
import com.ftwj.service.SysRoleMenuService;
import com.ftwj.vo.MenuVO;
import com.ftwj.vo.RoleVO;
import com.ftwj.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class SysRoleMenuServiceImpl implements SysRoleMenuService {
    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper;
    @Autowired
    private SysMenuListMapper sysMenuListMapper;

    @Override
    public void assignMenusToRole(String roleId, List<String> menuIds) {
        // 先删除角色的所有菜单权限
        sysRoleMenuMapper.deleteRoleMenusByRoleId(roleId);

        // 再添加新的菜单权限
        for (String menuId : menuIds) {
            SysRoleMenu sysRoleMenu = new SysRoleMenu();
            sysRoleMenu.setRoleId(roleId);
            sysRoleMenu.setMenuId(menuId);
            sysRoleMenu.setState(1);
            sysRoleMenu.setCreateTime(DateTime.now());
            sysRoleMenu.setUpdateTime(DateTime.now());
            sysRoleMenuMapper.insert(sysRoleMenu);
        }
    }


}